package com.woniuxy.kaer.user.controller;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.FileTypeUtil;
import com.woniuxy.kaer.commons.jwtUtil.JwtUtil;
import com.woniuxy.kaer.commons.util.Result;
import com.woniuxy.kaer.user.form.AddCarForm;
import com.woniuxy.kaer.user.param.AddCarParam;
import com.woniuxy.kaer.user.service.CarInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sun
 * @since 2025年02月17日
 */
@RestController
@RequestMapping("/carInfo")
@Api(tags = "车辆管理")
public class CarInfoController {
    @Resource
    private CarInfoService carInfoService;
    @Resource
    private JwtUtil jwtUtil;

    @ApiOperation("新增车辆")
    //新增车辆
    @PostMapping("/addCar")
    public Result addCar(@RequestBody AddCarForm form, @RequestHeader("token") String token)throws Exception{
        Integer userId = jwtUtil.getUserId(token);
//        //判断车辆是否是JPG或者png
//        String type = FileTypeUtil.getType(form.getCarPicture().getInputStream());
//        if(!"png".equals(type) && !"jpg".equals(type)){
//            throw new Exception("图片格式不正确");
//        }
        AddCarParam param = BeanUtil.toBean(form, AddCarParam.class);
        carInfoService.addCar(userId, param);
        return Result.succeed("新增车辆成功", null);
    }
}

